package A013executor;

import java.util.concurrent.*;

public class C003_Executors例子_Blocking {
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        final ExecutorService service = Executors.newFixedThreadPool(5);
        Future<String> result = service.submit(new Callable<String>() {
            @Override
            public String call() throws Exception {
                //模拟现实中的异步过程，等待五秒返回结果
                Thread.sleep(1000 * 5);
                System.out.println("call\t");
                return "ok";
            }
        });

        System.out.println("task begin...");
        //如果线程没有执行完成，那么继续等待，通过打印信息来直观感受线程执行过程
        while (result.isDone() == false) {
            System.out.println("wait for 1 second");
            Thread.sleep(1000);
        }
        String ok = result.get();
        service.shutdown();
        System.out.println("task end " + ok);
    }
}



